Battery = class('Battery', Feature)

function Battery:initialize(name, x, y, rotation, text, charge, visible)

	self.charge = charge or 0
	self.t = "battery"
	self.text = text or "You gain energy."
	self.name = name or "battery"
	self.visible = visible or true

	self:power()


	Feature.initialize(self, self.name, self.image, x, y, rotation, 0,0,0,0, self.t, self.visible)


end

function Battery:power()

	-- if the battery has power, show the battery on image
	-- if it does not, show the battery off image

	if self.charge > 0 then
		self.image = battery_on_img
	else
		self.image = battery_off_img
	end

end

function Battery:use()


	-- if the player has room for all the energy
	if player.battery+self.charge < player.max_bat then
		draw_text(self.text) -- display the batteries message
		player.battery = player.battery + self.charge -- charge the player up
		self.charge = self.charge - self.charge -- deplete batteries charge
		self:power() -- set battery image proper
		return true


	elseif player.battery == player.max_bat then
		draw_text("Your energy is already full.")

		return false


	else
		-- player only has room for some energy

		local pbr = player.max_bat - player.battery


		-- set player battery to full
		player.battery = player.max_bat

		draw_text(self.text)

		-- subtract power from battery
		self.charge = self.charge - pbr

		self:power()

		return true

	end

end

function Battery:update()

	Feature.update(self)

end
